import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description: 栈的模拟实现
 */

class MyStack{
    private int[] arr;
    private int usedSize = 0;
    private static final int DEFAULT_QUANTITY = 10;

    public MyStack() {
        this.arr = new int[DEFAULT_QUANTITY];
    }

    //push方法，向栈中增加元素
    public int push(int data) {
        if(isFull()) {
            arr = Arrays.copyOf(arr,arr.length * 2);
        }
        arr[usedSize] = data;
        usedSize++;
        return data;
    }

    //判断是否栈满
    public boolean isFull() {
        return usedSize == arr.length;
    }

    //让最上面的元素出栈
    public int pop() {
        if(empty()) {
            throw new MyEmptyStackException("栈为空！");
        }
        usedSize--;
        return arr[usedSize];
    }

    //查看最上面的元素但不出栈
    public int peek() {
        if(empty()) {
            throw new MyEmptyStackException("栈为空！");
        }
        return arr[usedSize - 1];
    }

    //判断栈是否为空
    public boolean empty() {
        return usedSize == 0;
    }


}



public class Test {
    public static void main(String[] args) {
        MyStack myStack = new MyStack();
        myStack.push(1);
        myStack.push(2);
        myStack.push(3);
        myStack.push(4);
        myStack.push(5);
        int x1 = myStack.peek();
        myStack.pop();
        myStack.pop();
        int x2 = myStack.pop();
        myStack.pop();
        boolean f1 = myStack.empty();
        myStack.pop();
        boolean f2 = myStack.empty();
        System.out.println(x1);
        System.out.println(x2);
        System.out.println(f1);
        System.out.println(f2);
    }
}
